﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace 充电桩上位机.Model.Title;

public class TitleButton : Button
{
    public static readonly DependencyProperty StatusProperty =
            DependencyProperty.Register(
                nameof(Status),
                typeof(bool),
                typeof(TitleButton),
                new PropertyMetadata(false, OnStatusChanged));

    public bool Status
    {
        get => (bool)GetValue(StatusProperty);
        set => SetValue(StatusProperty, value);
    }

    private static void OnStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is TitleButton button)
        {
            button.UpdateBackground();
        }
    }

    private void UpdateBackground()
    {
        Background = Status ? Brushes.Black : Brushes.White;
        Foreground = Status ? Brushes.White : Brushes.Black;
    }
}
